from pyecharts import options as opts
from pyecharts.charts import Graph

# 节点数据
nodes = [
    {"name": "消费需求不足", "symbolSize": 50},
    {"name": "社保水平偏低", "symbolSize": 45},
    {"name": "养老金差距", "symbolSize": 40},
    {"name": "储蓄率偏高", "symbolSize": 35},
    {"name": "代际转移压力", "symbolSize": 35},
    {"name": "国有资本积累", "symbolSize": 45},
    {"name": "资本市场不稳定", "symbolSize": 40},
    {"name": "协同改革方案", "symbolSize": 50},
    
    # 数据节点
    {"name": "居民储蓄率超国际20%", "symbolSize": 25},
    {"name": "城乡居民月均222元", "symbolSize": 25},
    {"name": "替代率仅5%-50%", "symbolSize": 25},
    {"name": "132万亿国有资本", "symbolSize": 25},
    
    # 措施节点
    {"name": "提高养老金水平", "symbolSize": 40},
    {"name": "划拨国有资本", "symbolSize": 40},
    {"name": "优化资产配置", "symbolSize": 35},
    {"name": "三支柱改革", "symbolSize": 35}
]

# 边数据
links = [
    {"source": "消费需求不足", "target": "储蓄率偏高"},
    {"source": "消费需求不足", "target": "代际转移压力"},
    {"source": "社保水平偏低", "target": "养老金差距"},
    {"source": "社保水平偏低", "target": "替代率仅5%-50%"},
    
    {"source": "居民储蓄率超国际20%", "target": "储蓄率偏高"},
    {"source": "城乡居民月均222元", "target": "养老金差距"},
    {"source": "替代率仅5%-50%", "target": "社保水平偏低"},
    
    {"source": "国有资本积累", "target": "132万亿国有资本"},
    {"source": "资本市场不稳定", "target": "优化资产配置"},
    
    {"source": "协同改革方案", "target": "提高养老金水平"},
    {"source": "协同改革方案", "target": "划拨国有资本"},
    {"source": "协同改革方案", "target": "三支柱改革"},
    
    {"source": "划拨国有资本", "target": "国有资本积累"},
    {"source": "划拨国有资本", "target": "资本市场不稳定"},
    
    {"source": "提高养老金水平", "target": "消费需求不足"},
    {"source": "优化资产配置", "target": "资本市场不稳定"}
]

# 生成知识图谱
c = (
    Graph()
    .add("", nodes, links,
         repulsion=200,
         linestyle_opts=opts.LineStyleOpts(curve=0.2),
         label_opts=opts.LabelOpts(is_show=True))
    .set_global_opts(
        title_opts=opts.TitleOpts(title="扩消费-强社保-稳股市协同改革知识图谱"),
        legend_opts=opts.LegendOpts(is_show=False),
        # 设置宽度和高度，这里将宽度设为 1200px，高度设为 800px
        toolbox_opts=opts.ToolboxOpts(is_show=True),
        graphic_opts=[opts.GraphicGroup(
            graphic_item=opts.GraphicItem(
                bounding="raw",
                left="center",
                top="center",
                z=-100,
            ),
            children=[
                opts.GraphicRect(
                    graphic_item=opts.GraphicItem(
                        left="center",
                        top="center",
                        z=-100,
                    ),
                    graphic_shape_opts=opts.GraphicShapeOpts(
                        width=1200,
                        height=800
                    ),
                    graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                        fill="rgba(255,255,255,0)"
                    )
                )
            ]
        )]
    )
)

# 输出HTML文件
c.render("促消费强社保.html")